package com.jt.controller;

import com.jt.service.FileService;
import com.jt.vo.ImageVO;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@RestController
@CrossOrigin
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;


    /**
     * 请求路径: http://localhost:8091/file/upload
     * 请求类型: post
     * 请求参数:file
     * 返回值:SysResult(ImageVO),参数返回ImageVO对象
     * ImageVO对象说明:virtualPath,urlPath,fileName
     */
    @PostMapping("/upload")
    public SysResult upload(MultipartFile file){ //MultipartFile高级输入流接口,不用使用InputStream等低效字节流

        ImageVO imageVO = fileService.upload(file);
        if(imageVO == null){
            return SysResult.fail();
        }

        return SysResult.success(imageVO);

    }





















}
